package ipc.project;

import java.util.ArrayList;
import java.util.List;
import java.util.Set;

import android.app.Activity;
import android.content.Context;
import android.content.res.ColorStateList;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

public class FriendsAdapter extends ArrayAdapter<Friend>{

    Context context; 
    int layoutResourceId;    
    List<Friend> data;
    
    public FriendsAdapter(Context context, int layoutResourceId, List<Friend> data) {
    	super(context, layoutResourceId, data);
        this.layoutResourceId = layoutResourceId;
        this.context = context;
        this.data = data;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        View row = convertView;
        FriendHolder holder = null;
        
        if(row == null)
        {
            LayoutInflater inflater = ((Activity)context).getLayoutInflater();
            row = inflater.inflate(layoutResourceId, parent, false);
            holder = new FriendHolder();
            holder.txtLogin = (TextView)row.findViewById(R.id.txtLogin);
            holder.txtStatus = (TextView)row.findViewById(R.id.txtStatus);
            row.setTag(holder);
        }
        else
        {
            holder = (FriendHolder)row.getTag();
        }
        Friend friend = data.get(position);
        holder.txtLogin.setText(friend.login);
        holder.txtStatus.setText(friend.status);
        return row;
    }
    
    static class FriendHolder
    {
    	TextView txtLogin;
        TextView txtStatus;
    }
}